<div class="container-fluid" style="margin: 0px 15px 0px 15px;">
<ol class="breadcrumb">
  <li><a href="<?php echo base_url('/index.php/inicio');?>">Início</a></li>
  <li><a href="<?php echo base_url('index.php/processos/consulta');?>">Processo</a></li>
  <li class="active">Novo</li>
</ol>
	<fieldset>
	<legend>Cadastro Processo</legend>
		<form class="form-horizontal" role="form" id="form" method="POST">
		<div class="form-group">
				<?php
					$attributes = array('class' => 'col-sm-2 control-label');
					echo form_label('Data Processo', '', $attributes);
				?>
			<div class="col-sm-2">
				<?php 
					$data = array('name'=> 'dia','id'=> 'dia','value'=> set_value('dia'),'placeholder'=> 'Data','class'=> 'form-control input-sm');
					echo form_input($data);
				?>
			</div>
			<div class="col-sm-2 control-label" style="text-align:left;color:red;">
				<?php echo form_error('dia');?>	
			</div>				
		</div>
		<div class="form-group">
		<label for="" class="col-sm-2 control-label">Tipo Processo</label>
		<div class="col-sm-2">
			<?php 
				echo form_dropdown('tipo_processo',$tipoprocesso,'','class="form-control input-sm" id="tipo_processo"');
			?>
		</div>
		<div class="col-sm-2 control-label" style="text-align:left;color:red;">
		<?php echo form_error('tipo_processo');?>	
		</div>	
		</div>

		<div class="form-group">
		<label for="" class="col-sm-2 control-label">Assunto</label>
		<div class="col-sm-3">
			<?php 
				$data = array('name'=> 'assunto','id'=> 'assunto','value'=> '','placeholder'=> 'Assunto','class'=> 'form-control input-sm');
				echo form_input($data);
			?>
		</div>
		<div class="col-sm-2 control-label" style="text-align:left;color:red;">
			<?php echo form_error('autor');?>	
		</div>	
		</div>
		<div class="form-group">
		<label for="" class="col-sm-2 control-label"></label>
			<div class="col-sm-2">
			<a data-toggle="modal" href="#" class="btn btn-primary btn-xs" data-target="#myassunto"><span class="glyphicon glyphicon-plus"></span>Cadastrar Assunto</a>
			</div>
		</div>
		<div class="form-group">
			<label for="" class="col-sm-2 control-label">Numero do Processo</label>
			<div class="col-sm-2">
				<?php 
					$data = array('name'=> 'numero_processo','id'=> 'numero_processo','value'=> @$processo->numeroprocesso,'placeholder'=> 'Numero do Processo','class'=> 'form-control input-sm');
					echo form_input($data);
					
				?>
				<br/>
				
			</div>
			<div class="col-sm-2 control-label" style="text-align:left;color:red;">
				<?php echo form_error('numero_processo');?>	
			</div>	
		</div>
		<div id="divparc" class="form-group">
		<label id="lbparce" class="col-sm-2 control-label">Parcelamento?</label>
		<div class="col-sm-2">
			<?php 
				$parcelamento = array('1'=>'SIM','2'=>'NAO');
				echo form_dropdown('parcelamento',$parcelamento,'2','class="form-control input-sm" id="parcelamento"');
			?>
		</div>
		<div class="col-sm-2 control-label" style="text-align:left;color:red;">
		<?php echo form_error('parcelamento');?>	
		</div>	
		</div>
		<div class="form-group" id="divparcelamento">
			<label id="lb_procenum" class="col-sm-2 control-label">Número Processo Parcelamento</label>
			<div class="col-sm-2">
				<?php 
					$data = array('name'=> 'numero_processo_parce','id'=> 'numero_processo_parce','value'=> @$processo->numeroprocesso,'placeholder'=> 'Num. do Processo','class'=> 'form-control input-sm');
					echo form_input($data);
					
				?>
			</div>
			<div class="col-sm-2 control-label" style="text-align:left;color:red;">
				<?php echo form_error('numero_processo_parce');?>	
			</div>	
		</div>
		
		<div class="form-group">
		<label id="lb_autor" class="col-sm-2 control-label">Requerente(s)</label>
		<div class="col-sm-3">
			<?php 
				$data = array('name'=> 'autor','id'=> 'autor','value'=> '','placeholder'=> 'Autor(es)','class'=> 'form-control input-sm');
				echo form_input($data);
			?>
		</div>
		<div class="col-sm-2 control-label" style="text-align:left;color:red;">
			<?php echo form_error('autor');?>	
		</div>	
		</div>
		<div class="form-group">
		<label id="lb_reu" class="col-sm-2 control-label">Requerido(s)</label>
		<div class="col-sm-3">
			<?php 
				$data = array('name'=> 'reu','id'=> 'reu','value'=> '','placeholder'=> 'Réu(s)','class'=> 'form-control input-sm');
				echo form_input($data);
			?>
		</div>
		<div class="col-sm-2 control-label" style="text-align:left;color:red;">
			<?php echo form_error('autor');?>	
		</div>	
		</div>
		
		<div class="form-group">
		<label for="" class="col-sm-2 control-label"></label>
			<div class="col-sm-2">
			<a data-toggle="modal" href="#" class="btn btn-primary btn-xs" data-target="#myModal"><span class="glyphicon glyphicon-plus"></span>Cadastrar Parte</a>
			</div>
		</div>
		
		<div class="form-group">
		<label for="" class="col-sm-2 control-label">Cód. Bic</label>
		<div class="col-sm-2">
			<?php
				$data = array('name'=> 'cod_bic','id'=> 'cod_bic','value'=>@$processo->cd_bic,'placeholder'=> 'Cód. Bic','class'=> 'form-control input-sm');
				echo form_input($data);
			?>
		</div>
		</div>  
		<div class="form-group">
		<label for="" class="col-sm-2 control-label">Observação</label>
		<div class="col-sm-5">
		  
			<?php 
				$data = array('name'=> 'observacao','id'=> 'observacao','placeholder'=> 'Observação','class'=> 'form-control input-sm','value'=>@$processo->observacao,'rows'=>'3');
				echo form_textarea($data);
			?>
		</div>
		</div>
		<div class="form-group">
		<label for="" class="col-sm-2 control-label">Responsavel</label>
		<div class="col-sm-2">
			<?php 
				$excecao = array('0'=>'PROJU','1'=>'IPPASA','2'=>'LICITAÇÃO','3'=>'PROCURADOR GERAL');
				echo form_dropdown('excecao',$excecao,'0','class="form-control input-sm" id="excecao"');
			?>
		</div>
		<div class="col-sm-2 control-label" style="text-align:left;color:red;">
		<?php echo form_error('excecao');?>	
		</div>	
		</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
			<?php 
				$data = array('name'=>'salvar','type' => 'submit','class' => 'btn btn-primary','content' =>'Salvar');
				echo form_button($data);
			?>
			<a id="cancelar" href="<?php echo base_url('index.php/processos/consulta');?>" class="btn btn-default"></span>Cancelar</a>
			</div>
		</div>
		</form>
	<div id="retorno1"></div>
	</fieldset>

</div>
		<!-- Modal -->
<div class="modal bs-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">		
		<form class='form-horizontal' role='form' id='form_parte' method="POST">
            <div class="modal-header btn-primary" >
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title">Cadastro Parte</h4>
            </div>
            <div class="modal-body">
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">Pessoa</label>
					<div class="col-sm-3">
						<?php 
							$tipo = array(''=>'', 'F'=>'Pessoa Física','J'=>'Pessoa Jurídica');
							echo form_dropdown('tipo',$tipo,'','class="form-control" id="tipo"');
						?>
					</div>
					<div class="col-sm-2 control-label" style="text-align:left;color:red;">
					<?php echo form_error('tipo');?>	
					</div>	
				</div>
				
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">CPF/CNPJ</label>
				<div class="col-sm-3">
					<?php 
						$data = array('name'=> 'cpf_cnpj','id'=> 'cpf_cnpj','value'=> @$parte->cpfcnpj,'placeholder'=> 'CPF','class'=> 'form-control input-sm');
						echo form_input($data);
					?>
				</div>
				</div>
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Nome</label>
				<div class="col-sm-4">
					<?php 
						$data = array('name'=> 'nome_parte','id'=> 'nome_parte','value'=> @$parte->nome_parte,'placeholder'=> 'Nome da Parte','class'=> 'form-control input-sm');
						echo form_input($data);
						
					?>
				</div>
				<div class="col-sm-2 control-label" style="text-align:left;color:red;">
				<?php echo form_error('nome_parte');?>	
				</div>	
				</div>
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Cargo</label>
				<div class="col-sm-3">
					<?php 
						$data = array('name'=> 'cargo','id'=> 'cargo','value'=> @$parte->cargo,'placeholder'=> 'Cargo','class'=> 'form-control input-sm');
						echo form_input($data);
					?>
				</div>
				</div>
				
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Endereco</label>
				<div class="col-sm-5">
					<?php 
						$data = array('name'=> 'endereco','id'=> 'endereco','value'=> @$parte->endereco,'placeholder'=> 'endereco','class'=> 'form-control input-sm');
						echo form_input($data);
					?>
				</div>
				</div>
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Cidade</label>
				<div class="col-sm-3">
					<?php 
						$data = array('name'=> 'cidade','id'=> 'cidade','value'=> @$parte->cidade,'placeholder'=> 'Cidade','class'=> 'form-control input-sm');
						echo form_input($data);
					?>
				</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">Estado</label>
					<div class="col-sm-3">
						<select class="form-control name="estado" id="estado">
							<option value="AC">Acre</option>
							<option value="AL">Alagoas</option>
							<option value="AM">Amazonas</option>
							<option value="AP">Amapá</option>
							<option value="BA">Bahia</option>
							<option value="CE">Ceará</option>
							<option value="DF">Distrito Federal</option>
							<option value="ES">Espirito Santo</option>
							<option value="GO">Goiás</option>
							<option value="MA">Maranhão</option>
							<option value="MG">Minas Gerais</option>
							<option value="MS">Mato Grosso do Sul</option>
							<option value="MT">Mato Grosso</option>
							<option value="PA">Pará</option>
							<option value="PB">Paraíba</option>
							<option value="PE">Pernambuco</option>
							<option value="PI">Piauí</option>
							<option selected value="PR">Paraná</option>
							<option value="RJ">Rio de Janeiro</option>
							<option value="RN">Rio Grande do Norte</option>
							<option value="RO">Rondônia</option>
							<option value="RR">Roraima</option>
							<option value="RS">Rio Grande do Sul</option>
							<option value="SC">Santa Catarina</option>
							<option value="SE">Sergipe</option>
							<option value="SP">São Paulo</option>
							<option value="TO">Tocantins</option>
						</select>
					</div>
					<div class="col-sm-2 control-label" style="text-align:left;color:red;">
					<?php echo form_error('tipo');?>	
					</div>	
				</div>
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Telefone</label>
				<div class="col-sm-2">
					<?php 
						$data = array('name'=> 'telefone','id'=> 'telefone','value'=> @$parte->telefone,'placeholder'=> 'Telefone','class'=> 'form-control input-sm');
						echo form_input($data);
					?>
				</div>
				</div>
			
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Descrição</label>
				<div class="col-sm-4">
					<?php 
						$data = array('name'=> 'descricao','id'=> 'descricao','placeholder'=> 'Descrição','class'=> 'form-control input-sm', 'value'=> @$parte->descricao,'rows'=>'3' );
						echo form_textarea($data);
					?>
				</div>
				</div>  
				<div id="retorno"></div>
			</div>
				<div class="modal-footer">
				<?php 
					//$data = array('name'=>'salvar','type' => 'button','class' => 'btn btn-default','content' =>'Salvar','onclick'=>'');
					//echo form_button($data);
				?>
				<button type="submit" class="btn btn-primary" id="modalparte" >Salvar</button>
				<a href="#" type="button"  data-dismiss="modal" class="btn btn-default">Cancelar</a>
				</div>
		</form>
		
    </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<div class="modal bs-example-modal-lg" id="myassunto" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">		
		<form class='form-horizontal' role='form' id='form_assunto' method="POST">
            <div class="modal-header btn-primary" >
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title">Cadastro Assunto</h4>

            </div>
            <div class="modal-body">
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Nome Assunto</label>
				<div class="col-sm-5">
					<?php 
						$data = array('name'=> 'assunto','id'=> 'assunto','value'=> '','placeholder'=> 'Nome Assunto','class'=> 'form-control input-sm');
						echo form_input($data);
						
					?>
				</div>
				<div class="col-sm-2 control-label" style="text-align:left;color:red;">
				<?php echo form_error('assunto');?>	
				</div>	
				</div>
				
				
			<div id="retorno3"></div>					
			</div>
				<div class="modal-footer">
				<button type="submit" class="btn btn-primary" id="modalassunto" >Salvar</button>
				<a href="#" type="button"  data-dismiss="modal" class="btn btn-default">Cancelar</a>
				
				</div>
		</form>
    </div>
        <!-- /.modal-content -->
		
    </div>
    <!-- /.modal-dialog -->
</div>
	<script src="<?php echo base_url('includes/js/jquery.tokeninput.js')?>"></script>
	<!--<script src="<?php echo base_url('includes/js/bootstrap-tokenfield.js')?>"></script>-->
	
	<link href="<?php echo base_url('includes/css/token-input-facebook.css') ?>" rel="stylesheet"> 
	<!--<link href="<?php echo base_url('includes/css/bootstrap-tokenfield.css') ?>" rel="stylesheet">
	<link href="<?php echo base_url('includes/css/tokenfield-typeahead.css') ?>" rel="stylesheet">-->
	
	<script language="javascript" type="text/javascript">
		$(document).ready(function(){
			
			$("#divparcelamento").hide();
			$("#dia").datepicker({dateFormat: "dd/mm/yy"});
			$('#numero_processo').focus();
			var checado = $("#parcelamento").is(":checked");
			if(checado == true){
				$("#divparcelamento").show();
			
			}
			$('#cod_bic').attr('readonly', true);
				$("#form").validate({
					ignore: [],
					rules: {
						dia: "required",
						tipo_processo: "required",
						numero_processo: { 
							required: true, 
							remote:'<?php echo base_url('index.php/processos/validaProcesso');?>'
						},
						numero_processo_parce: { 		
							required: false, 
							remote:'<?php echo base_url('index.php/processos/validaProcessoParcelamento');?>'
						},
						autor: "required",
						assunto: "required",
						reu: "required"
					},
					messages: {
						dia: "Campo requerido",
						tipo_processo: "Campo requerido",
						numero_processo: { required: 'Campo requerido', remote: ' Processo já cadastrado!' },
						numero_processo_parce: {remote: ' Processo nao cadastrado!' },
						autor: "Campo requerido",
						assunto: "Campo requerido",
						reu: "Campo requerido"
					},
					submitHandler: function(form){
						var dados = $('#form').serialize();
						$.ajax({
							type: "POST",
							url: "<?php echo base_url('index.php/processos/salvar'); ?>",
							data: dados,
							success: function( data )
							{
								alertify.alert(data);
								
								$('#dia').val('');
								$('#tipo_processo').val('');
								$('#numero_processo').val('');
								$('#numero_processo_parce').val('');
								$('#observacao').val('');
								$('#numero_processo').focus();
								
								
								/*$("html, body").animate({ scrollTop: $(document).height() }, "slow");
								if(data === 'OK'){
										
									$('#retorno1').html('<div class="alert alert-success" role="alert">CADASTRO EFETUADO COM SUCESSO</div>');
									setTimeout(function() {
										$('#retorno1').html('');
										window.location = "<?php echo base_url('index.php/processos/novo'); ?>";
									}, 2000);
								}else{
									$('#retorno1').html(data);
								}*/
							},
							statusCode: {
								404: function() {
									alertify.error("Pagina nao encontrada");
								}
							}
						});
						return false;
					}
				});
			
			$('#parcelamento').change( function(){
				if($(this).val() == 1){
					$("#divparcelamento").show();
					$("#numero_processo_parce").val('');
					
				}else if($(this).val() == 3){
					$("#divparcelamento").show();
					$("#numero_processo_parce").val('');
					
				}else{
					$("#divparcelamento").hide();
					$("#numero_processo_parce").val('');
				}

			});
			
			$('#tipo_processo').change( function(){
				if($(this).val() == 1){
					$('#cod_bic').attr('readonly', true);
					$("#divparc").show();
					$('#lbparce').html('Parcelamento');
					$('#lb_procenum').html('Número Processo Parcelamento');
					$('#lb_autor').html('Requerente(s)');
					$('#lb_reu').html('Requerido(s)');
					
					$("#lb_pergpar").hide();
					$("#parcelamento").val('2');
				}else if($(this).val() == 2){
					$('#cod_bic').val('');
					$('#cod_bic').attr('readonly', true);
					$('#lb_autor').html('Autor(es)');
					$('#lb_reu').html('Réu(s)');
					
					$("#divparcelamento").hide();
					$("#parcelamento").val('2');
					$("#divparc").hide();
				}else{
					$("#divparc").show();
					$('#cod_bic').attr('readonly', false);
					$('#lbparce').html('Embargos Execução');
					$('#lb_procenum').html('Número Processo Embargo');
					$('#lb_autor').html('Exequente(s)');
					$('#lb_reu').html('Executado(s)');
					
					$("#divparcelamento").hide();
					$("#parcelamento").val('2');
				}

			});
			
			$("#autor").tokenInput("<?php echo base_url('index.php/partes/consultaPartesJson');?>", {
		        	theme: "facebook",
					searchDelay:"50",
					preventDuplicates: "true"
					
			});
			
			$("#reu").tokenInput("<?php echo base_url('index.php/partes/consultaPartesJson');?>", {
		        	theme: "facebook",
					searchDelay:"50",
					preventDuplicates: "true"
					
			});
			var maskBehavior = function (val) {
				return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
			},
			options = {onKeyPress: function(val, e, field, options) {
					field.mask(maskBehavior.apply({}, arguments), options);
				}
			};
			
			$("#telefone").mask(maskBehavior, options);
			$("#modalparte").click(function(){
				$("#form_parte").validate({
					rules: {
						tipo: "required",
						nome_parte: "required"
						//cpf_cnpj: "required"
					},
					messages: {
						tipo: "Campo requerido",
						nome_parte: "Campo requerido"
						//cpf_cnpj: "Campo requerido"
					},
					submitHandler: function(form){
						var dados = $('#form_parte').serialize();
						$.ajax({
								type: "POST",
								url: "<?php echo base_url('index.php/partes/salvar');?>",
								data: dados,
								success: function( data )
								{
									if(data === 'OK'){
										$('#retorno').html('<div class="alert alert-success" role="alert">CADASTRO EFETUADO COM SUCESSO</div>');
										setTimeout(function() {
											$('#retorno').html('');
											$('#myModal').modal('hide');
										}, 2000);
										$('#tipo').val('');
										$('#cpf_cnpj').val('');
										$('#nome_parte').val('');
										$('#cargo').val('');
										$('#endereco').val('');
										$('#cidade').val('');
										$('#telefone').val('');
										$('#descricao').val('');
										
										//
									}else{
										$('#retorno').html(data);
									}
								}
						});
						return false;
					}
				});
			});
			$("#assunto").tokenInput("<?php echo base_url('index.php/assuntos/consultaAssuntoJson');?>", {
		        	theme: "facebook",
					searchDelay:"50",
					tokenLimit: "1",
					preventDuplicates: "true"
					
			});
			$("#modalassunto").click(function(){
				$("#form_assunto").validate({
					rules: {
						assunto: "required"
					},
					messages: {
						assunto: "Campo requerido"
					},
					submitHandler: function(form){
						var dados = $('#form_assunto').serialize();
						$.ajax({
								type: "POST",
								url: "<?php echo base_url('index.php/assuntos/salvarModal');?>",
								data: dados,
								success: function( data )
								{
									if(data === 'OK'){
										$('#retorno3').html('<div class="alert alert-success" role="alert">CADASTRO EFETUADO COM SUCESSO</div>');
										setTimeout(function() {
											$('#retorno3').html('');
											$('#myassunto').modal('hide');
										}, 2000);
										$('#assunto').val('');
										
										//
									}else{
										$('#retorno3').html(data);
									}
								}
						});
						return false;
					}
				});
			});
			$("#tipo").change(function(){
				 $('input[name=cpf_cnpj]').unmask();//Remove a mascara
				 if($(this).val()=="F"){//Acaso seja CPF
						$("input[name=cpf_cnpj]").mask("999.999.999-99");
						$("input[name=cpf_cnpj]").attr("placeholder","CPF");
				 } else {//Acaso seja Cnpj
						$("input[name=cpf_cnpj]").mask("99.999.999/9999-99");
						$("input[name=cpf_cnpj]").attr("placeholder","CNPJ");
				 }
			})
		});
		
			
	</script>
	</body>
</html>
